<%@ page import="cn.gpnu.domain.User" %><%--
  Created by IntelliJ IDEA.
  User: LOG
  Date: 2020/11/30
  Time: 22:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<body>
<input type="button" value="出售" id = "btn_02">
<input type="button" value="购买" id = "btn_01">
<input type="number" id = "id">
<script>
    var btn_01 = document.getElementById("btn_01");
    var btn_02 = document.getElementById("btn_02");

    var tree_id;
    var user_id = 1;
    function buytree() {
        $.ajax({
            url:"buytree_sevlet",
            type:"GET",
            data:{"tree_id":tree_id,"user_id":user_id},
            success:function (data) {
                alert("购买成功")
            },error:function () {
                alert("购买失败");
            }
        })
    }

    function selltree() {
        $.ajax({
            url:"selltree_servlet",
            type:"GET",
            data:{"tree_id":tree_id,"user_id":user_id},
            success:function (data) {
                alert("出售成功")
            },error:function () {
                alert("出售失败");
            }
        })
    }

    btn_01.onclick = function myFunction(){
        tree_id = document.getElementById("id").value;
        var x;
        var r = confirm("按下按钮!");
        if (r==true){
            alert("成功确认");
            buytree();
        }
        else{
            alert("失败");
        }
    }

    btn_02.onclick = function sellFunction(){
        tree_id = document.getElementById("id").value;
        var x;
        var r = confirm("确认卖出？");
        if (r==true){
            alert("已卖出");
            selltree();
        }
        else{
            alert("失败");
        }
    }
</script>
</body>
</html>
